/*
 * Benjamin I hope this is ok....it works looks ok...will work on that some more.
 * 
 */
package startupcompanymanager2012;

import javax.swing.DefaultComboBoxModel;
import javax.swing.JOptionPane;

/**
 *
 * @author blackuniverse
 */
public class StartupCompanyManager2012DevManager extends javax.swing.JFrame {

    private double hireCost = 1000;

    /** Creates new form StartupCompanyManager2012DevManager */
    public StartupCompanyManager2012DevManager() {
        initComponents();
        Core.calendarTimer.stop();
        devSelector.setModel(new DefaultComboBoxModel(Core.devs.toArray()));
        labelCompanyName.setText(Core.companyName);
        calcHireCost();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        staffInfoPanel = new javax.swing.JPanel();
        labelName = new javax.swing.JLabel();
        devName = new javax.swing.JLabel();
        labelAtt1 = new javax.swing.JLabel();
        devAtt1 = new javax.swing.JLabel();
        labelAtt2 = new javax.swing.JLabel();
        devAtt2 = new javax.swing.JLabel();
        labelAtt3 = new javax.swing.JLabel();
        devAtt3 = new javax.swing.JLabel();
        labelAtt4 = new javax.swing.JLabel();
        devAtt4 = new javax.swing.JLabel();
        labelProjectNum = new javax.swing.JLabel();
        devProjectNum = new javax.swing.JLabel();
        labelExp = new javax.swing.JLabel();
        devExp = new javax.swing.JLabel();
        labelCompanyName = new javax.swing.JLabel();
        labelLvl = new javax.swing.JLabel();
        devLvl = new javax.swing.JLabel();
        labelSalary = new javax.swing.JLabel();
        devSalary = new javax.swing.JLabel();
        labelCostNewDev = new javax.swing.JLabel();
        newDevCost = new javax.swing.JLabel();
        staffManagmentPanel = new javax.swing.JPanel();
        hireButton = new javax.swing.JButton();
        devSelector = new javax.swing.JComboBox();
        fireButton = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(startupcompanymanager2012.StartupCompanyManager2012App.class).getContext().getResourceMap(StartupCompanyManager2012DevManager.class);
        setTitle(resourceMap.getString("Developer Manager.title")); // NOI18N
        setName("Developer Manager"); // NOI18N
        setResizable(false);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosed(java.awt.event.WindowEvent evt) {
                frameDisposed(evt);
            }
        });

        staffInfoPanel.setBackground(resourceMap.getColor("staffInfoPanel.background")); // NOI18N
        staffInfoPanel.setName("staffInfoPanel"); // NOI18N
        staffInfoPanel.setPreferredSize(new java.awt.Dimension(350, 255));

        labelName.setFont(resourceMap.getFont("labelName.font")); // NOI18N
        labelName.setText(resourceMap.getString("labelName.text")); // NOI18N
        labelName.setName("labelName"); // NOI18N

        devName.setText(resourceMap.getString("devName.text")); // NOI18N
        devName.setName("devName"); // NOI18N

        labelAtt1.setFont(resourceMap.getFont("labelAtt4.font")); // NOI18N
        labelAtt1.setText(resourceMap.getString("labelAtt1.text")); // NOI18N
        labelAtt1.setName("labelAtt1"); // NOI18N

        devAtt1.setText(resourceMap.getString("devAtt1.text")); // NOI18N
        devAtt1.setName("devAtt1"); // NOI18N

        labelAtt2.setFont(resourceMap.getFont("labelAtt4.font")); // NOI18N
        labelAtt2.setText(resourceMap.getString("labelAtt2.text")); // NOI18N
        labelAtt2.setName("labelAtt2"); // NOI18N

        devAtt2.setText(resourceMap.getString("devAtt2.text")); // NOI18N
        devAtt2.setName("devAtt2"); // NOI18N

        labelAtt3.setFont(resourceMap.getFont("labelAtt4.font")); // NOI18N
        labelAtt3.setText(resourceMap.getString("labelAtt3.text")); // NOI18N
        labelAtt3.setName("labelAtt3"); // NOI18N

        devAtt3.setText(resourceMap.getString("devAtt3.text")); // NOI18N
        devAtt3.setName("devAtt3"); // NOI18N

        labelAtt4.setFont(resourceMap.getFont("labelAtt4.font")); // NOI18N
        labelAtt4.setText(resourceMap.getString("labelAtt4.text")); // NOI18N
        labelAtt4.setName("labelAtt4"); // NOI18N

        devAtt4.setText(resourceMap.getString("devAtt4.text")); // NOI18N
        devAtt4.setName("devAtt4"); // NOI18N

        labelProjectNum.setFont(resourceMap.getFont("labelAtt4.font")); // NOI18N
        labelProjectNum.setText(resourceMap.getString("labelProjectNum.text")); // NOI18N
        labelProjectNum.setName("labelProjectNum"); // NOI18N

        devProjectNum.setText(resourceMap.getString("devProjectNum.text")); // NOI18N
        devProjectNum.setName("devProjectNum"); // NOI18N

        labelExp.setFont(resourceMap.getFont("labelAtt4.font")); // NOI18N
        labelExp.setText(resourceMap.getString("labelExp.text")); // NOI18N
        labelExp.setName("labelExp"); // NOI18N

        devExp.setText(resourceMap.getString("devExp.text")); // NOI18N
        devExp.setName("devExp"); // NOI18N

        labelCompanyName.setFont(resourceMap.getFont("labelCompanyName.font")); // NOI18N
        labelCompanyName.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        labelCompanyName.setText(resourceMap.getString("labelCompanyName.text")); // NOI18N
        labelCompanyName.setName("labelCompanyName"); // NOI18N

        labelLvl.setFont(resourceMap.getFont("labelAtt4.font")); // NOI18N
        labelLvl.setText(resourceMap.getString("labelLvl.text")); // NOI18N
        labelLvl.setName("labelLvl"); // NOI18N

        devLvl.setText(resourceMap.getString("devLvl.text")); // NOI18N
        devLvl.setName("devLvl"); // NOI18N

        labelSalary.setFont(resourceMap.getFont("labelSalary.font")); // NOI18N
        labelSalary.setText(resourceMap.getString("labelSalary.text")); // NOI18N
        labelSalary.setName("labelSalary"); // NOI18N

        devSalary.setText(resourceMap.getString("devSalary.text")); // NOI18N
        devSalary.setName("devSalary"); // NOI18N

        labelCostNewDev.setText(resourceMap.getString("labelCostNewDev.text")); // NOI18N
        labelCostNewDev.setName("labelCostNewDev"); // NOI18N

        newDevCost.setText(resourceMap.getString("newDevCost.text")); // NOI18N
        newDevCost.setName("newDevCost"); // NOI18N

        javax.swing.GroupLayout staffInfoPanelLayout = new javax.swing.GroupLayout(staffInfoPanel);
        staffInfoPanel.setLayout(staffInfoPanelLayout);
        staffInfoPanelLayout.setHorizontalGroup(
            staffInfoPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(staffInfoPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(staffInfoPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(staffInfoPanelLayout.createSequentialGroup()
                        .addGroup(staffInfoPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, staffInfoPanelLayout.createSequentialGroup()
                                .addComponent(labelName)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(devName))
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, staffInfoPanelLayout.createSequentialGroup()
                                .addComponent(labelLvl)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(devLvl))
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, staffInfoPanelLayout.createSequentialGroup()
                                .addComponent(labelAtt4)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(devAtt4))
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, staffInfoPanelLayout.createSequentialGroup()
                                .addComponent(labelAtt3)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(devAtt3))
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, staffInfoPanelLayout.createSequentialGroup()
                                .addComponent(labelAtt2)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(devAtt2))
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, staffInfoPanelLayout.createSequentialGroup()
                                .addComponent(labelAtt1)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(devAtt1))
                            .addComponent(labelProjectNum, javax.swing.GroupLayout.Alignment.LEADING))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(devProjectNum))
                    .addGroup(staffInfoPanelLayout.createSequentialGroup()
                        .addComponent(labelExp)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(devExp))
                    .addGroup(staffInfoPanelLayout.createSequentialGroup()
                        .addComponent(labelSalary)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(devSalary))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, staffInfoPanelLayout.createSequentialGroup()
                        .addComponent(labelCostNewDev)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(newDevCost)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 75, Short.MAX_VALUE)
                        .addComponent(labelCompanyName)))
                .addContainerGap())
        );
        staffInfoPanelLayout.setVerticalGroup(
            staffInfoPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, staffInfoPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(staffInfoPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(staffInfoPanelLayout.createSequentialGroup()
                        .addComponent(labelCompanyName)
                        .addGap(11, 11, 11))
                    .addGroup(staffInfoPanelLayout.createSequentialGroup()
                        .addGroup(staffInfoPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(labelCostNewDev)
                            .addComponent(newDevCost))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)))
                .addGroup(staffInfoPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(labelName)
                    .addComponent(devName))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(staffInfoPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(labelLvl)
                    .addComponent(devLvl))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(staffInfoPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(labelAtt1)
                    .addComponent(devAtt1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(staffInfoPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(labelAtt2)
                    .addComponent(devAtt2))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(staffInfoPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(labelAtt3)
                    .addComponent(devAtt3))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(staffInfoPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(labelAtt4)
                    .addComponent(devAtt4))
                .addGap(27, 27, 27)
                .addGroup(staffInfoPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(labelProjectNum)
                    .addComponent(devProjectNum))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(staffInfoPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(labelExp)
                    .addComponent(devExp))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(staffInfoPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(labelSalary)
                    .addComponent(devSalary))
                .addGap(20, 20, 20))
        );

        getContentPane().add(staffInfoPanel, java.awt.BorderLayout.CENTER);

        staffManagmentPanel.setBackground(resourceMap.getColor("staffManagmentPanel.background")); // NOI18N
        staffManagmentPanel.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED, resourceMap.getColor("staffManagmentPanel.border.highlightOuterColor"), resourceMap.getColor("staffManagmentPanel.border.highlightInnerColor"), resourceMap.getColor("staffManagmentPanel.border.shadowOuterColor"), resourceMap.getColor("staffManagmentPanel.border.shadowInnerColor"))); // NOI18N
        staffManagmentPanel.setName("staffManagmentPanel"); // NOI18N
        staffManagmentPanel.setPreferredSize(new java.awt.Dimension(350, 30));

        hireButton.setText(resourceMap.getString("hireButton.text")); // NOI18N
        hireButton.setActionCommand(resourceMap.getString("hireButton.actionCommand")); // NOI18N
        hireButton.setName("hireButton"); // NOI18N
        hireButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                addDev(evt);
            }
        });

        devSelector.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        devSelector.setName("devSelector"); // NOI18N
        devSelector.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                viewStats(evt);
            }
        });

        fireButton.setText(resourceMap.getString("fireButton.text")); // NOI18N
        fireButton.setName("fireButton"); // NOI18N
        fireButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                fireDev(evt);
            }
        });

        javax.swing.GroupLayout staffManagmentPanelLayout = new javax.swing.GroupLayout(staffManagmentPanel);
        staffManagmentPanel.setLayout(staffManagmentPanelLayout);
        staffManagmentPanelLayout.setHorizontalGroup(
            staffManagmentPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(staffManagmentPanelLayout.createSequentialGroup()
                .addComponent(devSelector, javax.swing.GroupLayout.PREFERRED_SIZE, 138, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(22, 22, 22)
                .addComponent(hireButton)
                .addGap(18, 18, 18)
                .addComponent(fireButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        staffManagmentPanelLayout.setVerticalGroup(
            staffManagmentPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, staffManagmentPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(devSelector, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(fireButton)
                .addComponent(hireButton, javax.swing.GroupLayout.DEFAULT_SIZE, 23, Short.MAX_VALUE))
        );

        getContentPane().add(staffManagmentPanel, java.awt.BorderLayout.PAGE_START);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void addDev(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addDev

        

        if (Core.capital - hireCost >= 0) {



            if (Core.devs.size() < Core.office.getWorkstations()) {
                Core.capital -= hireCost;
                StartupCompanyManager2012View.updateBudgetLabel();
                Core.devs.add(new Developer());
                JOptionPane.showMessageDialog(null, "You just hired: " + Core.devs.get(Core.devs.size()-1).getName());

            } else {
                JOptionPane.showMessageDialog(null, "No more free Workstations! "
                        + "\nYou need to upgrade your office!");
            }
        } else {
            JOptionPane.showMessageDialog(null, "You don't have enough money for another developer!");
        }

        devSelector.setModel(new DefaultComboBoxModel(Core.devs.toArray()));
        viewStats(evt);
        calcHireCost();
    }//GEN-LAST:event_addDev

    private void fireDev(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_fireDev


        int selected = devSelector.getSelectedIndex();
        if (selected == 0) {
            JOptionPane.showMessageDialog(null, "You can't fire yourself!");
        } else {
            int faith = JOptionPane.showConfirmDialog(null, "Do you really want to fire this dev?");
            if (faith == JOptionPane.YES_OPTION == true) {
                Core.devs.remove(selected);
                Core.devs.toString();
                calcHireCost();
            }

        }
        devSelector.setModel(new DefaultComboBoxModel(Core.devs.toArray()));


    }//GEN-LAST:event_fireDev

    private void viewStats(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_viewStats
        int selected = devSelector.getSelectedIndex();
        devName.setText(Core.devs.get(selected).getName());
        devLvl.setText(Integer.toString(Core.devs.get(selected).getLevel()));
        devAtt1.setText(Integer.toString(Core.devs.get(selected).getBugsPerLine()));
        devAtt2.setText(Integer.toString(Core.devs.get(selected).getAcurracy()));
        devAtt3.setText(Integer.toString(Core.devs.get(selected).getSpeed()));
        devExp.setText(Integer.toString(Core.devs.get(selected).getExperiencePoints()));

    }//GEN-LAST:event_viewStats

    private void frameDisposed(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_frameDisposed
Core.calendarTimer.start();
    }//GEN-LAST:event_frameDisposed
    private void calcHireCost() {

        hireCost = 1000.00 + (Core.devs.size() * 500.00);
        newDevCost.setText("" + Core.nfmt.format(hireCost));


    }

    /**
     * @param args the command line arguments
     */
    public static void init(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
//devs.add(new Developer("DesSpielers", "Name"));



        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(StartupCompanyManager2012DevManager.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(StartupCompanyManager2012DevManager.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(StartupCompanyManager2012DevManager.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(StartupCompanyManager2012DevManager.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new StartupCompanyManager2012DevManager().setVisible(true);
            }
        });

    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel devAtt1;
    private javax.swing.JLabel devAtt2;
    private javax.swing.JLabel devAtt3;
    private javax.swing.JLabel devAtt4;
    private javax.swing.JLabel devExp;
    private javax.swing.JLabel devLvl;
    private javax.swing.JLabel devName;
    private javax.swing.JLabel devProjectNum;
    private javax.swing.JLabel devSalary;
    private javax.swing.JComboBox devSelector;
    private javax.swing.JButton fireButton;
    private javax.swing.JButton hireButton;
    private javax.swing.JLabel labelAtt1;
    private javax.swing.JLabel labelAtt2;
    private javax.swing.JLabel labelAtt3;
    private javax.swing.JLabel labelAtt4;
    private javax.swing.JLabel labelCompanyName;
    private javax.swing.JLabel labelCostNewDev;
    private javax.swing.JLabel labelExp;
    private javax.swing.JLabel labelLvl;
    private javax.swing.JLabel labelName;
    private javax.swing.JLabel labelProjectNum;
    private javax.swing.JLabel labelSalary;
    private javax.swing.JLabel newDevCost;
    private javax.swing.JPanel staffInfoPanel;
    private javax.swing.JPanel staffManagmentPanel;
    // End of variables declaration//GEN-END:variables
}
